package view.entities;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.geom.Arc2D;

import model.entities.MirrorOrientation;

/**
 * Draws Graphical Mirror's on a Mirror <JLabel> object 
 * 
 * @author ben
 *
 */
/**
 * 
 * TODO ONGOING: I was working on these to 
 * draw the game board graphics using code and	
 *  without using sprites. Good results, maybe 
 *  we can continue with this as a new game type.
 * 
 * 
 * 
 * 
 * @author ben
 *
 */
public class MirrorFactory implements IViewFactory {
	
	private MirrorOrientation orientation;
	private Dimension dimension;
	
	public MirrorFactory(MirrorOrientation orientation, Dimension dimension) {
		this.orientation = orientation;
		this.dimension = dimension;
	}

	public void buildMirror(Graphics2D g, double angle) {
		
		Graphics2D g2 = (Graphics2D) g.create();
		
		Arc2D leftArc = new Arc2D.Float();
		Arc2D rightArc = new Arc2D.Float();
		
		int lX = dimension.width / 2;
		int lY = dimension.height;
		int width = dimension.width;
		
		leftArc.setArcByTangent(new Point(lX - 2, 0), new Point(0, lY / 2), new Point(lX - 2, lY), width);
		leftArc.setAngleStart(150);
		leftArc.setAngleExtent(60);
		rightArc.setArcByTangent(new Point(lX + 2, 0), new Point(dimension.width, lY / 2), new Point(lX + 2, lY), width);
		rightArc.setAngleStart(-30);
		rightArc.setAngleExtent(60);
		
		
		g2.setColor(Color.ORANGE);
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		g2.setStroke(new BasicStroke(3f));
		
		g2.rotate(Math.toRadians(angle), dimension.width / 2, dimension.width / 2);
		
		g2.draw(leftArc);
		g2.draw(rightArc);
		
		g2.rotate(Math.toRadians(-angle), dimension.width / 2, dimension.width / 2);
		
	}

	@Override
	public void paintEntity(Graphics2D g2) {
		
		double angle = 0;
		
		switch (orientation) {
		case VERTICAL : angle = 0; break;
		case HORIZONTAL : angle = 90; break; 
		case NEGATIVE_SLOPE : angle = -45; break;
		case POSITIVE_SLOPE : angle = 45; break;
		case SLIGHT_DECLINE : angle = -67.5; break;
		case SLIGHT_RISE : angle = 67.5; break;
		case STEEP_DECLINE : angle = -22.5; break;
		case STEEP_RISE : angle = 22.5; break;
	
		}
		
		buildMirror(g2, angle);
	}
	
}
